<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px">
    <el-form-item label="作业编码" prop="workCode">
      <el-input v-model="dataForm.workCode" placeholder="作业编码"></el-input>
    </el-form-item>
    <el-form-item label="作业名称" prop="workName">
      <el-input v-model="dataForm.workName" placeholder="作业名称"></el-input>
    </el-form-item>
    <el-form-item label="作业提交时间" prop="workSubmitTime">
      <div class="block">
    <el-date-picker
      v-model="dataForm.workSubmitTime"
      type="datetime"
      placeholder="选择日期时间"
      value-format="yyyy-MM-dd HH:mm:ss">
    </el-date-picker>
  </div>
    </el-form-item>
    <el-form-item label="提交作业学生编号" prop="workSubmitStudentCode">
      <el-input v-model="dataForm.workSubmitStudentCode" placeholder="提交作业学生编号"></el-input>
    </el-form-item>
    <el-form-item label="提交作业学生姓名" prop="workSubmitStudentName">
      <el-input v-model="dataForm.workSubmitStudentName" placeholder="提交作业学生姓名"></el-input>
    </el-form-item>
    <el-form-item label="审核老师编号" prop="workAuditTeacherCode">
      <el-input v-model="dataForm.workAuditTeacherCode" placeholder="审核老师编号"></el-input>
    </el-form-item>
    <el-form-item label="审核老师姓名" prop="workAuditTeacherName">
      <el-input v-model="dataForm.workAuditTeacherName" placeholder="审核老师姓名"></el-input>
    </el-form-item>
    <el-form-item label="作业内容" prop="workContent">
      <el-input type="textarea"
          :rows="5"
          placeholder="请输入内容" v-model="dataForm.workContent"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          gmtCreate: '',
          createBy: '',
          gmtModified: '',
          lastModifiedBy: '',
          isDeleted: '',
          sortNo: '',
          version: '',
          workCode: '',
          workName: '',
          workContent: '',
          workSubmitTime: '',
          workSubmitStudentCode: '',
          workSubmitStudentName: '',
          workAuditTeacherCode: '',
          workAuditTeacherName: '',
          workSubmitStatus: '',
          workStatus: ''
        },
        dataRule: {
          gmtCreate: [
            { required: true, message: '记录创建时间不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '记录创建者不能为空', trigger: 'blur' }
          ],
          gmtModified: [
            { required: true, message: '记录更新时间不能为空', trigger: 'blur' }
          ],
          lastModifiedBy: [
            { required: true, message: '记录最后更新人不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(1删除,0未删除)不能为空', trigger: 'blur' }
          ],
          sortNo: [
            { required: true, message: '序号不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本不能为空', trigger: 'blur' }
          ],
          workCode: [
            { required: true, message: '作业编码不能为空', trigger: 'blur' }
          ],
          workName: [
            { required: true, message: '作业名称不能为空', trigger: 'blur' }
          ],
          workContent: [
            { required: true, message: '作业内容不能为空', trigger: 'blur' }
          ],
          workSubmitTime: [
            { required: true, message: '作业提交时间不能为空', trigger: 'blur' }
          ],
          workSubmitStudentCode: [
            { required: true, message: '提交作业学生编号不能为空', trigger: 'blur' }
          ],
          workSubmitStudentName: [
            { required: true, message: '提交作业学生姓名不能为空', trigger: 'blur' }
          ],
          workAuditTeacherCode: [
            { required: true, message: '审核老师编号不能为空', trigger: 'blur' }
          ],
          workAuditTeacherName: [
            { required: true, message: '审核老师姓名不能为空', trigger: 'blur' }
          ],
          workSubmitStatus: [
            { required: true, message: '作业提交状态(0_待提交,1_已提交,2_已过期)不能为空', trigger: 'blur' }
          ],
          workStatus: [
            { required: true, message: '作业状态(0_未完成,1_已完成,2_已过期)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/work/tworkinformation/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.gmtCreate = data.tWorkInformation.gmtCreate
                this.dataForm.createBy = data.tWorkInformation.createBy
                this.dataForm.gmtModified = data.tWorkInformation.gmtModified
                this.dataForm.lastModifiedBy = data.tWorkInformation.lastModifiedBy
                this.dataForm.isDeleted = data.tWorkInformation.isDeleted
                this.dataForm.sortNo = data.tWorkInformation.sortNo
                this.dataForm.version = data.tWorkInformation.version
                this.dataForm.workCode = data.tWorkInformation.workCode
                this.dataForm.workName = data.tWorkInformation.workName
                this.dataForm.workContent = data.tWorkInformation.workContent
                this.dataForm.workSubmitTime = data.tWorkInformation.workSubmitTime
                this.dataForm.workSubmitStudentCode = data.tWorkInformation.workSubmitStudentCode
                this.dataForm.workSubmitStudentName = data.tWorkInformation.workSubmitStudentName
                this.dataForm.workAuditTeacherCode = data.tWorkInformation.workAuditTeacherCode
                this.dataForm.workAuditTeacherName = data.tWorkInformation.workAuditTeacherName
                this.dataForm.workSubmitStatus = data.tWorkInformation.workSubmitStatus
                this.dataForm.workStatus = data.tWorkInformation.workStatus
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/work/tworkinformation/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'gmtCreate': this.dataForm.gmtCreate,
                'createBy': this.dataForm.createBy,
                'gmtModified': this.dataForm.gmtModified,
                'lastModifiedBy': this.dataForm.lastModifiedBy,
                'isDeleted': this.dataForm.isDeleted,
                'sortNo': this.dataForm.sortNo,
                'version': this.dataForm.version,
                'workCode': this.dataForm.workCode,
                'workName': this.dataForm.workName,
                'workContent': this.dataForm.workContent,
                'workSubmitTime': this.dataForm.workSubmitTime,
                'workSubmitStudentCode': this.dataForm.workSubmitStudentCode,
                'workSubmitStudentName': this.dataForm.workSubmitStudentName,
                'workAuditTeacherCode': this.dataForm.workAuditTeacherCode,
                'workAuditTeacherName': this.dataForm.workAuditTeacherName,
                'workSubmitStatus': this.dataForm.workSubmitStatus,
                'workStatus': this.dataForm.workStatus
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
